package com.sskj.finance.util;

import android.app.Activity;
import android.support.design.widget.BottomSheetDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.sskj.common.base.App;
import com.sskj.common.util.CheckUtil;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.finance.R;
import com.sskj.lib.util.CoinUtil;

public class TipFinanUtil {
    public static BottomSheetDialog showSupply(Activity activity, String available, String coin, OnInputList onInputList) {
        BottomSheetDialog codeDialog = new BottomSheetDialog(activity);
        View dialogView = LayoutInflater.from(activity)
                .inflate(R.layout.finan_bottom_sheet_supply, null);
        EditText etPwd = dialogView.findViewById(R.id.etPwd);
        EditText etNum = dialogView.findViewById(R.id.etNum);
        TextView tvAvailable = dialogView.findViewById(R.id.tvAvailable);
        tvAvailable.setText(String.format(App.INSTANCE.getString(R.string.finan_tipFinanUtil1_j), CoinUtil.keepCoinNumMax(coin,available), coin));
        Button mSubmit = dialogView.findViewById(R.id.btSubmit);
        codeDialog.setContentView(dialogView);


        ClickUtil.click(mSubmit, () -> {

            String pwd = etPwd.getText().toString().trim();
            String num = etNum.getText().toString().trim();
            if (TextUtils.isEmpty(num)) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.finan_tipFinanUtil2_j));
                return;
            }
            if (TextUtils.isEmpty(pwd)) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.finan_tipFinanUtil3_j));
                return;
            }
            if (!CheckUtil.isPayPwd(pwd)) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.finan_tipFinanUtil4_j));
                return;
            }
            if (Double.valueOf(num)>Double.valueOf(available)){
                ToastUtil.showShort(App.INSTANCE.getString(R.string.finan_tipFinanUtil5_j));
            }
            onInputList.onSure(num, pwd);

        });
        return codeDialog;
    }

    public interface OnInputList {
        void onSure(String... str);

    }
}
